﻿// Copyright (c) 2014 Jonathan Magnan (http://jonathanmagnan.com/).
// All rights reserved (http://zzzproject.com/sqlbulkcopy-extensions/).
// Licensed under MIT License (MIT) (https://zsqlbulkcopy.codeplex.com/license/).
using System;
using System.Collections.Generic;
using System.Data;

namespace Z.Net.Extensions
{
    internal partial class SqlBulkOperation
    {
        /// <summary>
        ///     Check if the single insert operation is valid.
        /// </summary>
        /// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
        /// <returns>true if the single insert operation is valid, false if not.</returns>
        public bool IsValidSingleInsert()
        {
            if (SqlBulkCopy.ColumnMappings.Count == 0)
            {
                throw new Exception("Column mapping must be specified for Bulk operation.");
            }

            if (!(DataSource is DataTable || DataSource is DataRow[] || DataSource is IDataReader || DataSource is IEnumerable<object>))
            {
                throw new Exception("Invalid datasource");
            }

            return true;
        }
    }
}